package com.neardrug.services.impl;

import com.neardrug.entity.*;
import com.neardrug.mapper.ExamplesMapper;
import com.neardrug.services.ExamplesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class ExamplesServiceImpl implements ExamplesService {

    @Autowired
    private ExamplesMapper examplesMapper;

    /**
     * 根据传递过来的Examples转为ExamplesInsert然后进行插入操作
     * @param examples
     */
    @Override
    public void insert(Examples examples) {
        List<ExamplesInsert> examplesInsertList=new ArrayList<>();
        ExamplesInsert examplesInsert=new ExamplesInsert();

        List<Synthesis> synthesisList = examples.getSynthesisList();
        for (int i = 0; i < synthesisList.size(); i++) {
            Synthesis synthesis = synthesisList.get(i);
            ChemicalCompound chemicalCompound = synthesis.getChemicalCompound();
            List<SynthesisProcess> synthesisProcessList = synthesis.getSynthesisProcessList();
            for (int j = 0; j < synthesisProcessList.size(); j++) {
                SynthesisProcess synthesisProcess = synthesisProcessList.get(j);
                examplesInsert=ExamplesInsert.builder()
                        .taskId(examples.getTaskId())
                        .fileName(examples.getFileName())
                        .fileUrl(examples.getFileUrl())
                        .exampleId(chemicalCompound.getExampleId())
                        .compoundId(chemicalCompound.getCompoundId())
                        .intermediateName(chemicalCompound.getIntermediateName())
                        .compoundName(chemicalCompound.getCompoundName())
                        .smiles(chemicalCompound.getSmiles())
                        .referenceReactions(chemicalCompound.getReferenceReactions())
                        .HNMR(chemicalCompound.getHNMR())
                        .CNMR(chemicalCompound.getCNMR())
                        .FNMR(chemicalCompound.getFNMR())
                        .PNMR(chemicalCompound.getPNMR())
                        .MS(chemicalCompound.getMS())
                        .IR(chemicalCompound.getIR())
                        .UV(chemicalCompound.getUV())
                        .Mp(chemicalCompound.getMp())
                        .Rf(chemicalCompound.getRf())
                        .AnalCalcd(chemicalCompound.getAnalCalcd())
                        .LCMS(chemicalCompound.getLCMS())
                        .HPLC(chemicalCompound.getHPLC())
                        .EXAMPLELABEL(chemicalCompound.getEXAMPLELABEL())
                        .REACTIONPRODUCT(chemicalCompound.getREACTIONPRODUCT())
                        .STARINGMATERIAL(chemicalCompound.getSTARINGMATERIAL())
                        .REAGENTCATALYST(chemicalCompound.getREAGENTCATALYST())
                        .SOLVENT(chemicalCompound.getSOLVENT())
                        .TIMES(chemicalCompound.getTIMES())
                        .TEMPERATURE(chemicalCompound.getTEMPERATURE())
                        .YIELDPERCENT(chemicalCompound.getYIELDPERCENT())
                        .YIELDOTHER(chemicalCompound.getYIELDOTHER())
                        .OTHERCOMPOUND(chemicalCompound.getOTHERCOMPOUND())

                        .stepId(synthesisProcess.getStepId())
                        .stepCompound(synthesisProcess.getStepCompound())
                        .stepDesc(synthesisProcess.getStepDesc())
                        .proReferenceReactions(synthesisProcess.getProReferenceReactions())
                        .proHNMR(synthesisProcess.getProHNMR())
                        .proCNMR(synthesisProcess.getProCNMR())
                        .proFNMR(synthesisProcess.getProFNMR())
                        .proPNMR(synthesisProcess.getProPNMR())
                        .proMS(synthesisProcess.getProMS())
                        .proIR(synthesisProcess.getProIR())
                        .proUV(synthesisProcess.getProUV())
                        .proMp(synthesisProcess.getProMp())
                        .proRf(synthesisProcess.getProRf())
                        .proAnalCalcd(synthesisProcess.getProAnalCalcd())
                        .proLCMS(synthesisProcess.getProLCMS())
                        .proHPLC(synthesisProcess.getProHPLC())
                        .proEXAMPLELABEL(synthesisProcess.getProEXAMPLELABEL())
                        .proREACTIONPRODUCT(synthesisProcess.getProREACTIONPRODUCT())
                        .proSTARINGMATERIAL(synthesisProcess.getProSTARINGMATERIAL())
                        .proREAGENTCATALYST(synthesisProcess.getProREAGENTCATALYST())
                        .proSOLVENT(synthesisProcess.getProSOLVENT())
                        .proTIMES(synthesisProcess.getProTIMES())
                        .proTEMPERATURE(synthesisProcess.getProTEMPERATURE())
                        .proYIELDPERCENT(synthesisProcess.getProYIELDPERCENT())
                        .proYIELDOTHER(synthesisProcess.getProYIELDOTHER())
                        .proOTHERCOMPOUND(synthesisProcess.getProOTHERCOMPOUND())
                        .build();
                examplesInsertList.add(examplesInsert);
            }
        }

        examplesMapper.insert(examplesInsertList);
    }
}
